package gemini.castor.ui.client.page.widget.dialog;

import com.google.gwt.event.shared.GwtEvent;

/**
 * This class presents an event for {@link GmnDialog}. 
 */
public class GmnDialogEvent extends GwtEvent<GmnDialogHandler> {

	private static Type<GmnDialogHandler> TYPE;
	
	private DialogActionType confirmType;
	
	public GmnDialogEvent(DialogActionType type) {
		this.confirmType = type;
	}
	
	/**
	 * The action type for {@link GmnDialogEvent}. 
	 */
	public enum DialogActionType {
		OK,
		CANCEL;
	}
	
	public static Type<GmnDialogHandler> getType() {
		if(TYPE == null) {
			TYPE = new Type<GmnDialogHandler>();
		}
		
		return TYPE;
	}
	
	@Override
	public Type<GmnDialogHandler> getAssociatedType() {
		return getType();
	}

	/**
	 * @param confirmType the confirmType to set
	 */
	public void setConfirmType(DialogActionType confirmType) {
		this.confirmType = confirmType;
	}

	/**
	 * @return the confirmType
	 */
	public DialogActionType getConfirmType() {
		return confirmType;
	}

	@Override
	protected void dispatch(GmnDialogHandler handler) {
		if(confirmType == DialogActionType.OK) {
			handler.onOK(this);
		} else {
			handler.onCancel(this);
		}
	}
	
}
